package com.okonna.selenium.tide.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

import com.okonna.selenium.tide.Application;
import com.okonna.selenium.tide.eventhandlers.genericevents.RunDumpTextListener;

public class TabInteractiveView
{
	private Composite cmpParent;
	private Composite cmpTabInteractiveView;
    private Application app;

    public TabInteractiveView(Composite tmpParent, Application tmpApp)
    {
		System.out.println(this.getClass().getSimpleName() + ".TabInteractiveView(" + tmpParent + ", " + tmpApp + ")");
		cmpParent = tmpParent;
		app = tmpApp;
    }

    public Composite initComposite(int intStyle)
    {
		System.out.println(this.getClass().getSimpleName() + ".initComposite()");
		cmpTabInteractiveView = new Composite(cmpParent, intStyle);
		cmpTabInteractiveView.setSize(640, 320);
		cmpTabInteractiveView.setLayout(new GridLayout(2, false));
		//cmpTabInteractiveView.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 1, 1));
	
		final Label lblURLPath = new Label(cmpTabInteractiveView, SWT.LEFT);
		lblURLPath.setText("URL Path:");
		// lblURLPath.setSize(lblURLPath.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		lblURLPath.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, true, 1, 1));
	
		final Text txtURLPath = new Text(cmpTabInteractiveView, SWT.SINGLE | SWT.BORDER);
		txtURLPath.setText("");
		// txtURLPath.setSize(txtURLPath.computeSize(SWT.DEFAULT, SWT.DEFAULT));
		txtURLPath.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 1, 1));
	
		final Label lblTarget = new Label(cmpTabInteractiveView, SWT.LEFT);
		lblTarget.setText("Target:");
		lblTarget.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, true, 1, 1));
	
		final Text txtTarget = new Text(cmpTabInteractiveView, SWT.SINGLE | SWT.BORDER);
		txtTarget.setText("");
		txtTarget.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 1, 1));
		
		final Label lblValue = new Label(cmpTabInteractiveView, SWT.LEFT);
		lblValue.setText("Value:");
		lblValue.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, true, 1, 1));
	
		final Text txtValue = new Text(cmpTabInteractiveView, SWT.SINGLE | SWT.BORDER);
		txtValue.setText("");
		txtValue.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 1, 1));
	
		final Button btnWaitCheck  = new Button(cmpTabInteractiveView, SWT.CHECK);
		btnWaitCheck.setText("Wait");
		btnWaitCheck.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, true, 1, 1));
	
		final Text txtWaitTime = new Text(cmpTabInteractiveView, SWT.SINGLE | SWT.BORDER);
		txtWaitTime.setText("5000");
		txtWaitTime.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 1, 1));
		
		final Button btnRun = new Button(cmpTabInteractiveView, SWT.PUSH);
		btnRun.setText("Run");
		btnRun.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, true, 1, 1));
	
		final Text txtResult = new Text(cmpTabInteractiveView, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.READ_ONLY);
		txtResult.setText("Please press 'Run' for result.");
		txtResult.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, true, 1, 5));
	
		btnRun.addSelectionListener(new RunDumpTextListener(app, txtURLPath, txtTarget, txtResult, btnWaitCheck, txtWaitTime));

		return cmpTabInteractiveView;
    }
}
